﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;

using eSYSU.Data.DataAccess;
using eSYSU.Web.Interface;
using eSYSU.Web.Entity;

namespace eSYSU.Web.Business
{
	/// <summary>
	/// 校园活动业务类
	/// </summary>
	public class ActivityService
	{
		public ActivityService()
		{
		}

		/// <summary>
		/// 插入一条活动记录
		/// </summary>
		/// <param name="college">活动模型对象</param>
		public static void ActivityInsert(Activity activity)
		{
			IDictionary<string, object> parmsDic = new Dictionary<string, object>();
			parmsDic.Add("@Name", activity.Title);
			parmsDic.Add("@ActiType", activity.Type);
			parmsDic.Add("@Brief", activity.Brief);
			parmsDic.Add("@Participant", activity.Participant);
			parmsDic.Add("@BeginTime", activity.BeginTime);
			parmsDic.Add("@EndTime", activity.EndTime);
			parmsDic.Add("@HoldPlace", activity.Address);
			parmsDic.Add("@Keyword", activity.Body);
			parmsDic.Add("@Poster", activity.Poster);
			parmsDic.Add("@Publisher", activity.Publisher);
			parmsDic.Add("@PubTime", activity.PublishTime);

			SqlHelper.ExecuteNonQuery(SqlHelper.ConnString, CommandType.StoredProcedure, "proc_Activity_Insert", parmsDic);
		}


		/// <summary>
		/// 获取指定活动的记录（ID为零则获取全部活动记录）
		/// </summary>
		/// <param name="iCollegeID">活动编号（ID为零则获取全部活动记录）</param>
		/// <returns>包含指定活动的记录DataTable对象</returns>
		public static DataTable GetActivities(int activityId)
		{
			if (activityId > -1)
			{
				IDictionary<string, object> parmsDic = new Dictionary<string, object>();
				parmsDic.Add("@_id", activityId);

				return SqlHelper.GetDataTable(SqlHelper.ConnString, CommandType.StoredProcedure, "proc_Activity_Get", parmsDic);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 创建活动海报的缩略图
		/// </summary>
		/// <param name="sOriginalLogoPath">用于生成缩略图的Poster源图地址</param>
		/// <param name="sDestinationLogoPaths">缩略图生成路径（包含扩展名）的字符串数组</param>
		/// <param name="iSize">缩略图的尺寸（与路径数组长度要一致）</param>
		/// <returns>生成结果</returns>
		public static bool CreatePosterThumbnail(string sOriginalPosterPath, string[] sDestinationPosterPaths, int[,] iSize)
		{
			try
			{
				for (int i = 0; i < sDestinationPosterPaths.Length; i++)
				{
					eSYSU.Web.Common.ImageHelper.CreateThumbnail(sOriginalPosterPath, sDestinationPosterPaths[i], iSize[i, 0], iSize[i, 1]);
				}
				return true;
			}
			catch
			{
				return false;
			}
		}
	}
}